{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "63b244c5",
   "metadata": {},
   "source": [
    "# VoxCeleb1 --- Listen to different videos from speaker"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4f7d9e0d",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "os.chdir('../..')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8bafcc2b",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import soundfile as sf\n",
    "import IPython.display as ipd\n",
    "from glob import glob\n",
    "import shutil\n",
    "from pathlib import Path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2f466190",
   "metadata": {},
   "outputs": [],
   "source": [
    "def listen_to_different_videos_from_speaker(speaker=270, save=True):\n",
    "    speaker_ = f'id1{speaker:04d}'\n",
    "    videos = glob(f'data/voxceleb1/{speaker_}/*')\n",
    "    videos = [v.split('/')[-1] for v in videos]\n",
    "\n",
    "    for i, video in enumerate(videos):\n",
    "        path = f'data/voxceleb1/{speaker_}/{video}/00001.wav'\n",
    "        data, sr = sf.read(path)\n",
    "        data = data.reshape((1, -1)).astype(np.float32)\n",
    "        print(f'Video: {video}')\n",
    "        ipd.display(ipd.Audio(data, rate=sr))\n",
    "        print()\n",
    "        \n",
    "        if save:\n",
    "            dst = f'different_videos_same_speaker/{speaker}'\n",
    "            Path(dst).mkdir(parents=True, exist_ok=True)\n",
    "            shutil.copyfile(path, f'{dst}/{i}.wav')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8d5a81f2",
   "metadata": {},
   "outputs": [],
   "source": [
    "listen_to_different_videos_from_speaker(speaker=270, save=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a19a81aa",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
